﻿
// Condition: 6. Write a method that returns the index of the first element in array that is bigger than its neighbors, or -1, if there’s no such element.

using System;


class FirstBigger
{
    // check for each element in array if it is bigger than its neighbor
    // no matter if neighbors are one or two 
    static int Answer(int[] array)
    {
        for ( int index = 0; index < array.Length; index++)
        {
            if (index==0 )
            {
                if (array[0] > array[1])
                {
                    return array[0];
                }
            }
            if (index == array.Length - 1)
            {
                if (array[array.Length - 1] > array[array.Length - 2])
                {
                    return array[index];
                }
            }
            if ( index!=0 && index!=array.Length - 1)
            {
                if (array[index] > array[index + 1] && array[index] > array[index - 1])
                {
                    return array[index];
                }
            }
        }
        // if there is no bigger than the others
        return -1;     
    }

    static void Main(string[] args)
    {
        Console.Write("Enter number of elements in the array: ");
        int element = int.Parse(Console.ReadLine());
        int[] array = new int[element];
        // read array elements from console
        for (int i = 0; i < element; i++)
        {
            Console.Write("Element[{0}] = ", i);
            array[i] = int.Parse(Console.ReadLine());
        }

        // print the array
        Console.Write("The array is {");
        for (int i = 0; i < array.Length; i++)
        {
            Console.Write(array[i] + " ");
        }
        Console.Write("}");

        Console.WriteLine();


        // output information
        if (Answer(array) == -1)
        {
            Console.WriteLine("There is no element bigger than it's neighbor");
        }
        else
        {
            Console.WriteLine("First bigger element than it's neightbor is: {0}", Answer(array));
        }

    }

}
